using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using System.Collections.Generic;


public partial class UserDefinedFunctions
{
	protected static readonly Random rnd = new Random();

    //[SqlFunction(TableDefinition = "randomvalue bigint", FillRowMethodName = "RandomListFill")]
    //public static System.Collections.IEnumerable RandomList(SqlInt64 max, SqlInt32 count)
    //{
    //    if (count.Value > max.Value)
    //        throw new Exception("Count must be less or equal to max.");

    //    SortedDictionary<long, long> list = new SortedDictionary<long, long>();

    //    int i = 0;
    //    while (i < count.Value)
    //    {
    //        long rndval;
    //        if (max.Value > (long)int.MaxValue)
    //            rndval = (rnd.Next(int.MaxValue) * rnd.Next(int.MaxValue)) % max.Value + 1;
    //        else
    //            rndval = rnd.Next((int)max.Value) + 1;

    //        // looking for duplicates
    //        if (list.ContainsKey(rndval))
    //            continue;

    //        //add to the list
    //        list.Add(rndval, rndval);
    //        i++;
    //    }

    //    foreach (KeyValuePair<long, long> v in list)
    //        yield return v.Value;
    //}

	public static void RandomListFill(object value, out SqlInt64 randomvalue)
	{
		randomvalue = new SqlInt64((long)value);
	}
};
